package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Moble     string `gorm:"type:varchar(100);not null;commit:'手机号'"`
	Password  string `gorm:"type:varchar(100);not null;commit:'密码'"`
	HeadImage string `gorm:"type:varchar(500);not null;commit:'头像'"`
	NickName  string `gorm:"type:varchar(30);not null;commit:'昵称'"`
	Age       int64  `gorm:"type:char(11);not null;commit:'年龄'"`
	Email     string `gorm:"type:varchar(30);not null;commit:'邮箱'"`
	Address   string `gorm:"type:varchar(30);not null;commit:'地址'"`
}

// realname 真实名称
func (u *User) FindOrCreate(db *gorm.DB, moble string) error {
	return db.Debug().Where("moble=?", moble).FirstOrCreate(u).Error
}

func (u *User) FIndUserBY(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(u).Error
}

func (u *User) UpdateUser(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}

type UserLogin struct {
	gorm.Model
	Mobile string `gorm:"type:varchar(100);not null;commit:'手机号'"`
	Ip     string `gorm:"type:varchar(100);not null;commit:'手机号'"`
}

func (l *UserLogin) UserLoginCreate(db *gorm.DB) error {
	return db.Debug().Create(l).Error
}
